package com.group.project.hrms.service.impl;

import com.group.project.hrms.entity.SalaryBaseWithHold;
import com.group.project.hrms.mapper.SalaryBaseWithHoldMapper;
import com.group.project.hrms.service.ISalaryBaseWithHoldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SalaryBaseWithHoldService implements ISalaryBaseWithHoldService {

    @Autowired
    private SalaryBaseWithHoldMapper salaryBaseWithHoldMapper;


    @Override
    public int insertSalaryBaseWithHold(SalaryBaseWithHold salaryBaseWithHold) {
        return salaryBaseWithHoldMapper.insert(salaryBaseWithHold);
    }

    @Override
    public int deleteSalaryBaseWithHold(SalaryBaseWithHold salaryBaseWithHold) {
        return salaryBaseWithHoldMapper.deleteByPrimaryKey(salaryBaseWithHold);
    }

    @Override
    public int updateSalaryBaseWithHold(SalaryBaseWithHold salaryBaseWithHold) {
        return salaryBaseWithHoldMapper.updateByPrimaryKey(salaryBaseWithHold);
    }

    @Override
    public SalaryBaseWithHold selectOneSalaryBaseWithHold(SalaryBaseWithHold salaryBaseWithHold) {
        return null;
    }

    @Override
    public SalaryBaseWithHold selectOneSalaryBaseWithHoldByFileMonthAndContactID(String fileMonth, String cid) {
        Example example = new Example(SalaryBaseWithHold.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("fileMonth", "%" + fileMonth + "%");
        criteria.andEqualTo("contactId", cid);
        return salaryBaseWithHoldMapper.selectOneByExample(example);
    }

    @Override
    public List<SalaryBaseWithHold> selectSalaryBaseWithHoldByMonth(String month) { //month: 2022-06
        Example example = new Example(SalaryBaseWithHold.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.orLike("fileMonth", "%" + month + "%");
        return salaryBaseWithHoldMapper.selectByExample(example);
    }

    @Override
    public List<SalaryBaseWithHold> selectAllSalaryBaseWithHold() {
        return salaryBaseWithHoldMapper.selectAll();
    }
}
